import requests,os
from  lxml import etree
from urllib import request,parse


base_url = 'http://www.tupianzj.com/meinv/mm/meizitu/'


response = request.urlopen(url=base_url)

text = response.read().decode('gbk')
html = etree.HTML(text)
# 创建路径
targetPath = os.getcwd() + os.path.sep + 'b' + os.path.sep
# 判断路径存不存在
if not os.path.exists(targetPath):
    # 创建文件夹
    os.makedirs(targetPath)
# print(text)

res = html.xpath('//img/@src')


# 下载图片
for item in res:
    targetPath2 = (targetPath+item.split("/")[-1])

    print(item)
    request.urlretrieve(item,targetPath2)

